

#pragma once

#include <string>
#include "Status.h"


namespace streamdb {

class File {
public:
    File(const std::string &fname) ;
    ~File();

    const std::string &getFileName() const {
        return fname;
    }

    Status openRW();
    Status close();
    Status getSize(uint64_t & size);

    Status readUint64(uint64_t & value);
    Status read(char * buf, uint64_t & sz);

    Status writeUint64(const uint64_t value);
    Status write(const char * buf, uint64_t & cap);

    Status writeByPosition(const uint64_t pos, const char * buf, uint64_t & cap);

    Status seekBegin();
    Status seekEnd();
    Status seekOffset(uint64_t offset);
    Status getCurPos(uint64_t & curPos);
    Status flush();
private:
    std::string fname;
    int fd;
};

}//namespace streamdb
